%by clq
%need to input best_is,opt_profits,opt_profits_pref,profits_R,profits_RP
%p=(0.1,0.5,0.9)
%call_in_sequence=[2 2 1 3 3 3 3 3 2 2 1 2 3 3 3 3 1 1 2 1 3 1 2 3 1 1 1 2 3 1 2 3 3 1 2 1 3 3 2 2 2 1 1 2 1 1 2 1]
function figure2(j_all, N)
figure(2)

global P
P = [.1, .5, .9];

[best_is, opt_profits, ~, ~, ~] = prop_policy(j_all, N);
[~, profits_R, ~, ~, ~] = round_robin(j_all, N);

pref = randi([1, 2], 1, N);
[~, opt_profits_pref] = prop_pref(j_all, pref);
[~, profits_RP] = round_robin_pref(j_all, pref);


n = length(best_is);

%first draw the expected profit
yyaxis left;
plot(1:n,opt_profits,'-');
hold on; 
plot(1:n,profits_R,'--');
hold on; 
plot(1:n,opt_profits_pref,'.:');
hold on; 
plot(1:n,profits_RP,'.--');
legend('Proposed Policy','Round Robin','Prop. Policy with Pref.','Round Robin with Pref.','Location','NorthWest')

%then mark the best slot
yyaxis right;
hold on; 
stem(1:n,best_is,'o:','HandleVisibility','off');

%labels on the axis
ylim([0 9])
yticks([1:8]);
yticklabels({'1:(0,2,3)','2:(1,1,2)','3:(2,2,1)','4:(2,2,1)','5:(1,0,2)','6:(3,1,2)','7:(0,0,2)','8:(2,1,1)'});

yyaxis left;
ylabel('Expected Profit');
xlabel('Sequence of patient types');
xlim([0 49]);
xticks([1:48]);
xticklabels({'2','2','1','3','3','3','3','3','2','2','1','2','3','3','3','3','1','1','2','1','3','1','2','3','1','1','1','2','3','1','2','3','3','1','2','1','3','3','2','2','2','1','1','2','1','1','2','1'});


%lines and marks (to be adjusted)
hold on; 
line([28,28],[0,1800],'LineWidth',3,'HandleVisibility','off');
hold on; 
line([34,34],[0,1800],'LineWidth',3,'HandleVisibility','off');
annotation('textarrow',[0.53 0.57],[0.89 0.89],'string','Patient 28');
annotation('textarrow',[0.71 0.67],[0.89 0.89],'string','Patient 34');
annotation('textarrow',[0.495 0.495],[0.72 0.67],'string','Patient 23');
annotation('textarrow',[0.683 0.683],[0.49 0.54],'string','Patient 35');
annotation('textarrow',[0.81 0.81],[0.389 0.444],'string','Patient 43');